<?php 

class EnhancedSearchView extends View {

	protected $movieList;
	
	function __construct() {
		
	}
	
	function getMovieList() {
		return $this->movieList;
	}
	
	function setMovieList($m) {
		$this->movieList = $m;
	}
	
	function display() {
		echo '<form action="" method="POST">';
		echo '<table border="0">';
		echo '<tr><td>Actor:</td><td><input type="text" name="actor" /></td></tr>';
		echo '<tr><td></td><td><select name="ar"><option value="AND">AND</option><option value="OR">OR</option></select></td></tr>';
		echo '<tr><td>Director:</td><td><input type="text" name="director" /></td></tr>';
		echo '<tr><td></td><td><select name="dr"><option value="AND">AND</option><option value="OR">OR</option></select></td></tr>';
		echo '<tr><td>Title:</td><td><input type="text" name="title" /></td></tr>';
		echo '<tr><td></td><td><select name="tr"><option value="AND">AND</option><option value="OR">OR</option></select></td></tr>';
		echo '<tr><td>Rating:</td><td>'.$this->generateRatingDropdown().'</td></tr>';
		echo '<tr><td>Order by:</td><td>'.$this->generateOrderByDropdown().'</td></tr>';
		echo '<input type="hidden" name="action" value="save" />';
		echo '<tr><td></td><td><input type="submit" value="search" class="btn btn-default" /></td></tr>';
		echo '</table>';
		echo '</form>';
		
		if ($this->movieList) {
			$size = sizeof($this->movieList);
			if ($size > 0) {
				echo '<div style="width:90%; margin-top:20px;">';
				echo '<table class="table table-striped">';
				echo '<thead><th>id</th><th>Title</th><th>Year of release</th><th>Director</th><th>Rating</th><th>Copies Available</th><th>Price</th></thead>';
				foreach ($this->movieList as $movie) {
					echo '<tr><td>'.$movie->getId().'</td><td><a href="?page=buy&view=movie&movieId='.$movie->getId().'&movieName='.$movie->getTitle().'&noCopies='.$movie->getNoCopies().'">'.$movie->getTitle().'</a></td>
						<td>'.$movie->getYear().'</td>
						<td>'.$movie->getDirectorFirstName().' '.$movie->getDirectorLastName().'</td>
						<td>'.$movie->getRating().'</td>
						<td>'.$movie->getNoCopies().'</td>
						<td>'.$movie->getPrice().'</td>
						</tr>';
				}
				echo '</table>';
				echo '</div>';
			}
		}
	}
	
	function generateRatingDropdown() {
		$s = '<select name="rating">';
		$s = $s.'<option value="G">G</option>';
		$s = $s. '<option value="PG">PG</option>';
		$s = $s. '<option value="PG-13">PG-13</option>';
		$s = $s. '<option value="R">R</option>';
		$s = $s. '<option value="NC-17">NC-17</option>';
		$s = $s. '</select>';
		return $s;
	}
	
	function generateOrderByDropdown() {
		$s = '<select name="orderby">';
		$s = $s.'<option value="director">director</option>';
		$s = $s.'<option value="title">title</option>';
		$s = $s.'<option value="rating">rating</option>';
		$s = $s.'</select>';
		return $s;
	}

}